package pe.edu.pucp.dp1.gui.vista;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import pe.edu.pucp.dp1.gui.controlador.GestorGUI;
import pe.edu.pucp.dp1.lectura.controlador.GestorCar;
import pe.edu.pucp.dp1.procesamiento.controlador.GestorInterseccion;

public class MiniMapa extends JPanel {

    public static GestorGUI gestorGUI = GestorGUI.getInstance();

    private int posX = 0;
    private int posY = 160;
    private boolean[][] zonasPatron;
    BufferedImage buffMap;

    Color color10 = new Color(255, 0, 0);
    Color color9 = new Color(255, 20, 0);
    Color color8 = new Color(255, 40, 0);
    Color color7 = new Color(255, 60, 0);
    Color color6 = new Color(255, 80, 0);
    Color color5 = new Color(255, 100, 0);
    Color color4 = new Color(255, 120, 0);
    Color color3 = new Color(255, 140, 0);
    Color color2 = new Color(255, 160, 0);
    Color color1 = new Color(255, 180, 0);
    Color color0 = new Color(255, 200, 0);

    public MiniMapa() {

    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        Graphics grafMap;
        try {
            buffMap = ImageIO.read(getClass().getResource("/pe/edu/pucp/dp1/gui/imagenes/cuadro240x160.jpg"));//Puede usar fondo

        } catch (Exception e) {
            System.out.println("error");
        }
        grafMap = buffMap.getGraphics();

        ActMiniMapa(grafMap);

        g.drawImage(buffMap, 0, 0, null);//this  

        g.setColor(Color.ORANGE);

        g.fillRect(posX - 3, 160 - (posY + 3), 5, 5);
        g.setColor(Color.BLACK);

        g.drawRect(posX - 3, 160 - (posY + 3), 5, 5);
    }

    public void ActMiniMapa(Graphics g) {
        //g.setColor(Color.white);

        for (int i = 0; i < 240; i++) {
            for (int j = 0; j < 160; j++) {
                if ((i % 4 == 0) && (j % 4 == 0)) {
                    if (gestorGUI.getMiniMapa()[i][j] == 11) {
                        g.setColor(color10);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 10) {
                        g.setColor(color9);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 9) {
                        g.setColor(color8);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 8) {
                        g.setColor(color7);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 7) {
                        g.setColor(color6);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 6) {
                        g.setColor(color5);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 5) {
                        g.setColor(color4);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 4) {
                        g.setColor(color3);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 3) {
                        g.setColor(color2);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 2) {
                        g.setColor(color1);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 1) {
                        g.setColor(color0);
                        g.fillRect(i, j, 4, 4);
                    }
                    if (gestorGUI.getMiniMapa()[i][j] == 0) {
                        g.setColor(Color.LIGHT_GRAY);
                        g.fillRect(i, j, 4, 4);
                    }
                }
            }
        }

    }

    public void setPosX(int posX) {
        this.posX = posX;
    }

    public void setPosY(int posY) {
        this.posY = posY;
    }

    public boolean[][] getZonasPatron() {
        return zonasPatron;
    }

}
